<?php
/**
 * Created by PhpStorm.
 * User: 刘红波 <liuhb@cqjcdflzxsws.com>
 * Date: 2018/11/22
 * Time: 15:24
 */

namespace app\sd\admin;


use app\admin\controller\Admin;
use app\sd\model\WeReport as WeReportModel;
use app\common\builder\ZBuilder;

class WeReport extends Admin
{

    public function index()
    {
        $map = $this->getMap()?$this->getMap():[];
        $model = new WeReportModel();
        $dataList = $model->reportList($map);
        $columns = [
            ['id', '举报ID'],
            ['user_id', '举报人ID'],
            ['type', '内容类型', 'callback', function ($value) {
                switch ($value) {
                    case 1:
                        return '话题';
                    case 2:
                        return '回复';
                    default:
                        return '话题';
                }
            },'__data__'],
            ['value', '被举报内容ID'],
            ['reported_user_id','被举报人ID'],
            ['is_handled', '是否处理','callback',function($value,$data){
                switch ($value) {
                    case 1:
                        return '<a href='.url('delete',['ids'=>$data['id']]).'><h6 style="color: green">已处理</h6>//点击删除已处理记录</a>';
                    case 2:
                        return '<h6 style="color: red">未处理</h6>';
                    default:
                        return '<h6 style="color: red">未处理</h6>';
                }
            },'__data__'],
            ['comment', '举报描述'],
            ['right_button', '管理按键', 'btn']
        ];


        $right_buttons = [
            'delete_content'=>[
                'title'=>'删除被举报内容',
                'icon'=>'fa fa-times',
                'href'=>url('we_topic/delete',['ids'=>'__value__','is_handled'=>1,'type'=>'__type__'])
            ]
            ,
            'reset_name' =>[
                'href' => url('we_users/resetNickName',['id'=>'__reported_user_id__']),
                'title' => '重置昵称',
                'icon' => 'fa fa-cogs'
            ],
        ];
        return ZBuilder::make('table')
            ->setPageTitle('举报管理')
            ->addColumns($columns)
            ->setRowList($dataList)
            ->addTopSelect('type','内容类型',['1'=>'话题','2'=>'回复'])
            ->addTopSelect('is_handled','是否处理',['1'=>'已处理','0'=>'未处理'])
            ->setSearch(['user_id'=>'举报人ID','reported_user_id','被举报人id','value'=>'举报内容id','举报ID','content'=>'举报描述'])
            ->setTableName('we_report')
            ->setColumnWidth([
                'id'  => 40,
                'user_id' => 40,
                'type'=>40,
                'value'=>40,
                'is_handled'=>40,
                'reported_user_id'=>40
            ])
            ->addRightButtons($right_buttons)
            ->fetch();
    }
}